import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

export function sanitizeForTableName(name: string): string {
  // 允许字母、数字、下划线和中文字符
  // 移除非法字符，并将空格替换为下划线
  return name.replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g, '').replace(/\s+/g, '_');
}

export function sanitizeForColumnName(name: string): string {
  // 移除所有对于列名非法的字符
  // 将空格和特殊字符替换为下划线
  let sanitized = name.replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g, '_');
  // 如果首字符是数字，则添加前缀
  if (/^\d/.test(sanitized)) {
    sanitized = '_' + sanitized;
  }
  return sanitized;
}
